/*
 * <one line to give the program's name and a brief idea of what it does.>
 * Copyright (C) 17-ago-2011 lichfolky
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see http://www.gnu.org/licenses/.
 * 
 * Copyright (C) 17-ago-2011 lichfolky
 * This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you
 * are welcome to redistribute it under certain conditions;
 */

/*
 * EnvironmentJPanel.java
 *
 * Created on 17-ago-2011, 14.44.22
 */
package rescue2011;

import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;

/**
 *
 * @author lichfolky
 */
public class EnvironmentJPanel extends javax.swing.JPanel {

    static int DEBRIS = 0;
    static int EMPTY = 1;
    static int GATE = 2;
    static int OUTDOOR = 3;
    static int WALL = 4;
    private final int[][] grid;
    private final ImageIcon[] images;

    @SuppressWarnings("empty-statement")
    public EnvironmentJPanel() {
        super();
        images = new ImageIcon[5];
        images[DEBRIS] = new ImageIcon("./src/Images/debris.jpg");
        images[EMPTY] = new ImageIcon("./src/Images/empty.jpg");
        images[GATE] = new ImageIcon("./src/Images/gate.jpg");
        images[OUTDOOR] = new ImageIcon("./src/Images/outdoor.jpg");
        images[WALL] = new ImageIcon("./src/Images/wall.jpg");
//        grid = new int[3];
        int[][] aux = {
            {1, 1, 2, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 4, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 4, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 3, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 2, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 1, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 1, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 3, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 4, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 0, 3, 4, 1, 0, 1, 0, 1, 3},
            {0, 1, 2, 3, 4, 1, 0, 1, 0, 1, 3}
        };
        grid = aux;
//        this.setSize(grid.length*100, grid[0].length*70);
    }

    @Override
    public Dimension getSize() {
        return new Dimension(grid.length*100, grid[0].length*100);
    }
    public void setElement(int x, int y, int z){
        grid[x][y] = z;
    }
    /** Creates new form EnvironmentJPanel
     * @param grid
     */
    public EnvironmentJPanel(int[][] grid) {
        super();
        images = new ImageIcon[5];
        images[DEBRIS] = new ImageIcon("/Users/lichfolky/NetBeansProjects/RescueAiLab/src/Images/debris.jpg");
        images[EMPTY] = new ImageIcon("/Users/lichfolky/NetBeansProjects/RescueAiLab/src/Images/empty.jpg");
        images[GATE] = new ImageIcon("/Users/lichfolky/NetBeansProjects/RescueAiLab/src/Images/gate.jpg");
        images[OUTDOOR] = new ImageIcon("/Users/lichfolky/NetBeansProjects/RescueAiLab/src/Images/outdoor.jpg");
        images[WALL] = new ImageIcon("/Users/lichfolky/NetBeansProjects/RescueAiLab/src/Images/wall.jpg");

        this.grid = grid;
    }

    /**
     *
     * @param g
     */
    @Override
    public void paintComponent(Graphics g) {
        if (grid != null) {
            for (int i = 0; i < grid.length; i++) {
                for (int j = 0; j < grid[i].length; j++) {
                g.drawImage(images[grid[i][j]].getImage(), j * 90, i*80, 100, 100, this);
                }
            }
        }
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
